package test.datetime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by linshuo on 2017/12/18.
 */
public class DateUtil {
    public static Date getYesterdayDate(Date date) {
        /* 获取前一天 */
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1); // 前一天
        Date yesterDay = calendar.getTime();
        /* 格式化,干掉时分秒*/
        SimpleDateFormat myformat = new SimpleDateFormat("yyyy-MM-dd");
        String temp = myformat.format(yesterDay);
        Date yesterDayFormat = null;
        try {
            yesterDayFormat = myformat.parse(temp);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return yesterDayFormat;
    }

    public static Date getCurrentTime() {
        return new Date();
    }
}
